{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "# import seaborn as sns\n",
    "# import matplotlib.pyplot as plt\n",
    "import os\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.linear_model import Lasso, LogisticRegression\n",
    "from sklearn.preprocessing import RobustScaler\n",
    "from sklearn.feature_selection import SelectFromModel\n",
    "from feature_selection import embedded_method\n",
    "# plt.style.use('seaborn-colorblind')\n",
    "# %matplotlib inline\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_breast_cancer\n",
    "data = load_breast_cancer()\n",
    "data = pd.DataFrame(np.c_[data['data'], data['target']],\n",
    "                  columns= np.append(data['feature_names'], ['target']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean radius</th>\n",
       "      <th>mean texture</th>\n",
       "      <th>mean perimeter</th>\n",
       "      <th>mean area</th>\n",
       "      <th>mean smoothness</th>\n",
       "      <th>mean compactness</th>\n",
       "      <th>mean concavity</th>\n",
       "      <th>mean concave points</th>\n",
       "      <th>mean symmetry</th>\n",
       "      <th>mean fractal dimension</th>\n",
       "      <th>...</th>\n",
       "      <th>worst texture</th>\n",
       "      <th>worst perimeter</th>\n",
       "      <th>worst area</th>\n",
       "      <th>worst smoothness</th>\n",
       "      <th>worst compactness</th>\n",
       "      <th>worst concavity</th>\n",
       "      <th>worst concave points</th>\n",
       "      <th>worst symmetry</th>\n",
       "      <th>worst fractal dimension</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17.99</td>\n",
       "      <td>10.38</td>\n",
       "      <td>122.80</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>0.11840</td>\n",
       "      <td>0.27760</td>\n",
       "      <td>0.3001</td>\n",
       "      <td>0.14710</td>\n",
       "      <td>0.2419</td>\n",
       "      <td>0.07871</td>\n",
       "      <td>...</td>\n",
       "      <td>17.33</td>\n",
       "      <td>184.60</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.1622</td>\n",
       "      <td>0.6656</td>\n",
       "      <td>0.7119</td>\n",
       "      <td>0.2654</td>\n",
       "      <td>0.4601</td>\n",
       "      <td>0.11890</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.57</td>\n",
       "      <td>17.77</td>\n",
       "      <td>132.90</td>\n",
       "      <td>1326.0</td>\n",
       "      <td>0.08474</td>\n",
       "      <td>0.07864</td>\n",
       "      <td>0.0869</td>\n",
       "      <td>0.07017</td>\n",
       "      <td>0.1812</td>\n",
       "      <td>0.05667</td>\n",
       "      <td>...</td>\n",
       "      <td>23.41</td>\n",
       "      <td>158.80</td>\n",
       "      <td>1956.0</td>\n",
       "      <td>0.1238</td>\n",
       "      <td>0.1866</td>\n",
       "      <td>0.2416</td>\n",
       "      <td>0.1860</td>\n",
       "      <td>0.2750</td>\n",
       "      <td>0.08902</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>19.69</td>\n",
       "      <td>21.25</td>\n",
       "      <td>130.00</td>\n",
       "      <td>1203.0</td>\n",
       "      <td>0.10960</td>\n",
       "      <td>0.15990</td>\n",
       "      <td>0.1974</td>\n",
       "      <td>0.12790</td>\n",
       "      <td>0.2069</td>\n",
       "      <td>0.05999</td>\n",
       "      <td>...</td>\n",
       "      <td>25.53</td>\n",
       "      <td>152.50</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>0.1444</td>\n",
       "      <td>0.4245</td>\n",
       "      <td>0.4504</td>\n",
       "      <td>0.2430</td>\n",
       "      <td>0.3613</td>\n",
       "      <td>0.08758</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11.42</td>\n",
       "      <td>20.38</td>\n",
       "      <td>77.58</td>\n",
       "      <td>386.1</td>\n",
       "      <td>0.14250</td>\n",
       "      <td>0.28390</td>\n",
       "      <td>0.2414</td>\n",
       "      <td>0.10520</td>\n",
       "      <td>0.2597</td>\n",
       "      <td>0.09744</td>\n",
       "      <td>...</td>\n",
       "      <td>26.50</td>\n",
       "      <td>98.87</td>\n",
       "      <td>567.7</td>\n",
       "      <td>0.2098</td>\n",
       "      <td>0.8663</td>\n",
       "      <td>0.6869</td>\n",
       "      <td>0.2575</td>\n",
       "      <td>0.6638</td>\n",
       "      <td>0.17300</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.29</td>\n",
       "      <td>14.34</td>\n",
       "      <td>135.10</td>\n",
       "      <td>1297.0</td>\n",
       "      <td>0.10030</td>\n",
       "      <td>0.13280</td>\n",
       "      <td>0.1980</td>\n",
       "      <td>0.10430</td>\n",
       "      <td>0.1809</td>\n",
       "      <td>0.05883</td>\n",
       "      <td>...</td>\n",
       "      <td>16.67</td>\n",
       "      <td>152.20</td>\n",
       "      <td>1575.0</td>\n",
       "      <td>0.1374</td>\n",
       "      <td>0.2050</td>\n",
       "      <td>0.4000</td>\n",
       "      <td>0.1625</td>\n",
       "      <td>0.2364</td>\n",
       "      <td>0.07678</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   mean radius  mean texture  mean perimeter  mean area  mean smoothness  \\\n",
       "0        17.99         10.38          122.80     1001.0          0.11840   \n",
       "1        20.57         17.77          132.90     1326.0          0.08474   \n",
       "2        19.69         21.25          130.00     1203.0          0.10960   \n",
       "3        11.42         20.38           77.58      386.1          0.14250   \n",
       "4        20.29         14.34          135.10     1297.0          0.10030   \n",
       "\n",
       "   mean compactness  mean concavity  mean concave points  mean symmetry  \\\n",
       "0           0.27760          0.3001              0.14710         0.2419   \n",
       "1           0.07864          0.0869              0.07017         0.1812   \n",
       "2           0.15990          0.1974              0.12790         0.2069   \n",
       "3           0.28390          0.2414              0.10520         0.2597   \n",
       "4           0.13280          0.1980              0.10430         0.1809   \n",
       "\n",
       "   mean fractal dimension   ...    worst texture  worst perimeter  worst area  \\\n",
       "0                 0.07871   ...            17.33           184.60      2019.0   \n",
       "1                 0.05667   ...            23.41           158.80      1956.0   \n",
       "2                 0.05999   ...            25.53           152.50      1709.0   \n",
       "3                 0.09744   ...            26.50            98.87       567.7   \n",
       "4                 0.05883   ...            16.67           152.20      1575.0   \n",
       "\n",
       "   worst smoothness  worst compactness  worst concavity  worst concave points  \\\n",
       "0            0.1622             0.6656           0.7119                0.2654   \n",
       "1            0.1238             0.1866           0.2416                0.1860   \n",
       "2            0.1444             0.4245           0.4504                0.2430   \n",
       "3            0.2098             0.8663           0.6869                0.2575   \n",
       "4            0.1374             0.2050           0.4000                0.1625   \n",
       "\n",
       "   worst symmetry  worst fractal dimension  target  \n",
       "0          0.4601                  0.11890     0.0  \n",
       "1          0.2750                  0.08902     0.0  \n",
       "2          0.3613                  0.08758     0.0  \n",
       "3          0.6638                  0.17300     0.0  \n",
       "4          0.2364                  0.07678     0.0  \n",
       "\n",
       "[5 rows x 31 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((455, 30), (114, 30))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(data.drop(labels=['target'], axis=1), \n",
    "                                                    data.target, test_size=0.2,\n",
    "                                                    random_state=0)\n",
    "X_train.shape, X_test.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Lasso\n",
    "Regularization with Lasso.Lasso (L1) has the property that is able to shrink some of the coefficients to zero. Therefore, that feature can be removed from the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RobustScaler(copy=True, quantile_range=(25.0, 75.0), with_centering=True,\n",
       "       with_scaling=True)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# linear models benefit from feature scaling\n",
    "\n",
    "scaler = RobustScaler()\n",
    "scaler.fit(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:433: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n",
      "  FutureWarning)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "SelectFromModel(estimator=LogisticRegression(C=1, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='warn',\n",
       "          n_jobs=None, penalty='l1', random_state=None, solver='warn',\n",
       "          tol=0.0001, verbose=0, warm_start=False),\n",
       "        max_features=None, norm_order=1, prefit=False, threshold=None)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# fit the LR model\n",
    "sel_ = SelectFromModel(LogisticRegression(C=1, penalty='l1'))\n",
    "sel_.fit(scaler.transform(X_train), y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total features: 30\n",
      "selected features: 14\n",
      "features with coefficients shrank to zero: 16\n"
     ]
    }
   ],
   "source": [
    "# make a list with the selected features\n",
    "selected_feat = X_train.columns[(sel_.get_support())]\n",
    "\n",
    "print('total features: {}'.format((X_train.shape[1])))\n",
    "print('selected features: {}'.format(len(selected_feat)))\n",
    "print('features with coefficients shrank to zero: {}'.format(\n",
    "    np.sum(sel_.estimator_.coef_ == 0)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['mean radius', 'mean perimeter', 'mean area', 'mean smoothness',\n",
       "       'mean compactness', 'mean concavity', 'mean fractal dimension',\n",
       "       'texture error', 'perimeter error', 'smoothness error',\n",
       "       'concavity error', 'concave points error', 'symmetry error',\n",
       "       'worst radius', 'worst perimeter', 'worst compactness'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we can identify the removed features like this:\n",
    "removed_feats = X_train.columns[(sel_.estimator_.coef_ == 0).ravel().tolist()]\n",
    "removed_feats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((455, 14), (114, 14))"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# remove the features from the training and testing set\n",
    "\n",
    "X_train_selected = sel_.transform(X_train.fillna(0))\n",
    "X_test_selected = sel_.transform(X_test.fillna(0))\n",
    "\n",
    "X_train_selected.shape, X_test_selected.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Random Forest Importance\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feature ranking:\n",
      "1. feature no:27 feature name:worst concave points (0.206316)\n",
      "2. feature no:22 feature name:worst perimeter (0.147163)\n",
      "3. feature no:7 feature name:mean concave points (0.100672)\n",
      "4. feature no:20 feature name:worst radius (0.082449)\n",
      "5. feature no:6 feature name:mean concavity (0.060420)\n",
      "6. feature no:2 feature name:mean perimeter (0.048284)\n",
      "7. feature no:23 feature name:worst area (0.046151)\n",
      "8. feature no:3 feature name:mean area (0.038594)\n",
      "9. feature no:13 feature name:area error (0.035627)\n",
      "10. feature no:0 feature name:mean radius (0.030476)\n",
      "11. feature no:10 feature name:radius error (0.028711)\n",
      "12. feature no:26 feature name:worst concavity (0.028533)\n",
      "13. feature no:12 feature name:perimeter error (0.019986)\n",
      "14. feature no:21 feature name:worst texture (0.018623)\n",
      "15. feature no:1 feature name:mean texture (0.013840)\n",
      "16. feature no:25 feature name:worst compactness (0.013195)\n",
      "17. feature no:29 feature name:worst fractal dimension (0.011840)\n",
      "18. feature no:24 feature name:worst smoothness (0.008988)\n",
      "19. feature no:28 feature name:worst symmetry (0.008973)\n",
      "20. feature no:18 feature name:symmetry error (0.007378)\n",
      "21. feature no:11 feature name:texture error (0.006736)\n",
      "22. feature no:15 feature name:compactness error (0.005464)\n",
      "23. feature no:19 feature name:fractal dimension error (0.005117)\n",
      "24. feature no:16 feature name:concavity error (0.004957)\n",
      "25. feature no:8 feature name:mean symmetry (0.004660)\n",
      "26. feature no:4 feature name:mean smoothness (0.004614)\n",
      "27. feature no:9 feature name:mean fractal dimension (0.003689)\n",
      "28. feature no:17 feature name:concave points error (0.002993)\n",
      "29. feature no:5 feature name:mean compactness (0.002844)\n",
      "30.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Hp1l7xOlM4SA3nznb\n/LiquhW60AIeO8XSTwC2An+Y5O+SvDfJflOsN9YO/s+nXivJW5JsAV4OnL8I9Zf1Q6d3AJ+sqqlv\n85z6i7m9hwJbRqZnmdIBflKGP5Bkf+DDwGvnnCmcwZQDcb7aSd4AbAP+aJr1+1r7AquBD027Vl9v\nvv29GPamGxr4g6p6GvBtuqGmRbOY2z+uVlW9oapW0D23zptm/b7efVX1VLpXsccmedK0a86pv5jb\nm3FdmHLNBWk+/JPsQ/fH8UdV9X9G5u8NvAS4bAlqnwm8CHh59QOJU3YS8Lmqun3ahebZ5tuTHNwv\nP5juDHFaZoHZkbPPK+gOBotivv/zJap1CfCz0+zDqH547SrgxMWqOcdibO8ssGJk+jDglinXXJCm\nw78f038fcENVvXPO4hOAL1XV7GLWTnIi8DpgdVV9Zxq1x5j6KxzY4f5eB5zZ3z8T+Oi0+lBVtwFb\nkhzdzzoeuH5a9Ubt5Pm2KLWSHDXSbDXwpSn3Y/n2K9aSPIz+72qaNefUX9TtBa4FjkpyZP+K+nS6\n5/dup+lP+CZ5NvBXwN8D9/ezX19V65O8H7i6qt61mLWB3wMeAtzZz7u6qs6dRh/6fjycbozyCVX1\njWnV6WvNt83XAJcDhwNfBU6rqrvGrmSYfjwVeC/d1RibgVdV1d3TqjdSd97n22LVAs4Gju7n3Qyc\nW1X/NHT9kX48me5N/GV0J5uXV9UFU6r1QWCG7quUbwd+HTiZRdzevh8nA/+Dbpsvqqq3TLPeQjUd\n/pLUqqaHfSSpVYa/JDXI8JekBhn+ktQgw1+SGmT4S1KDDH9JatD/B2TJhsaWure9AAAAAElFTkSu\nQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model = embedded_method.rf_importance(X_train=X_train,y_train=y_train,\n",
    "                             max_depth=10,top_n=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['mean concavity', 'mean concave points', 'worst radius',\n",
       "       'worst perimeter', 'worst concave points'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select features whose importance > threshold\n",
    "from sklearn.feature_selection import SelectFromModel\n",
    "\n",
    "# only 5 features have importance > 0.05\n",
    "feature_selection = SelectFromModel(model, threshold=0.05,prefit=True) \n",
    "selected_feat = X_train.columns[(feature_selection.get_support())]\n",
    "selected_feat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['mean radius', 'mean perimeter', 'mean area', 'mean concavity',\n",
       "       'mean concave points', 'radius error', 'area error', 'worst radius',\n",
       "       'worst perimeter', 'worst area', 'worst concavity',\n",
       "       'worst concave points'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# only 12 features have importance > 2 times median\n",
    "feature_selection2 = SelectFromModel(model, threshold='2*median',prefit=True) \n",
    "selected_feat2 = X_train.columns[(feature_selection2.get_support())]\n",
    "selected_feat2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Gradient Boosted Trees Importance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feature ranking:\n",
      "1. feature no:27 feature name:worst concave points (0.694636)\n",
      "2. feature no:23 feature name:worst area (0.131077)\n",
      "3. feature no:4 feature name:mean smoothness (0.033800)\n",
      "4. feature no:8 feature name:mean symmetry (0.018609)\n",
      "5. feature no:22 feature name:worst perimeter (0.015998)\n",
      "6. feature no:21 feature name:worst texture (0.013732)\n",
      "7. feature no:2 feature name:mean perimeter (0.010792)\n",
      "8. feature no:26 feature name:worst concavity (0.010138)\n",
      "9. feature no:17 feature name:concave points error (0.008941)\n",
      "10. feature no:13 feature name:area error (0.008934)\n",
      "11. feature no:0 feature name:mean radius (0.007928)\n",
      "12. feature no:12 feature name:perimeter error (0.006268)\n",
      "13. feature no:18 feature name:symmetry error (0.005472)\n",
      "14. feature no:3 feature name:mean area (0.005069)\n",
      "15. feature no:1 feature name:mean texture (0.005034)\n",
      "16. feature no:10 feature name:radius error (0.004299)\n",
      "17. feature no:16 feature name:concavity error (0.003595)\n",
      "18. feature no:6 feature name:mean concavity (0.003354)\n",
      "19. feature no:19 feature name:fractal dimension error (0.003092)\n",
      "20. feature no:14 feature name:smoothness error (0.002149)\n",
      "21. feature no:29 feature name:worst fractal dimension (0.001952)\n",
      "22. feature no:25 feature name:worst compactness (0.001149)\n",
      "23. feature no:9 feature name:mean fractal dimension (0.000942)\n",
      "24. feature no:11 feature name:texture error (0.000917)\n",
      "25. feature no:15 feature name:compactness error (0.000671)\n",
      "26. feature no:5 feature name:mean compactness (0.000636)\n",
      "27. feature no:20 feature name:worst radius (0.000354)\n",
      "28. feature no:24 feature name:worst smoothness (0.000305)\n",
      "29. feature no:28 feature name:worst symmetry (0.000145)\n",
      "30. feature no:7 feature name:mean concave points (0.000013)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEICAYAAACktLTqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAF71JREFUeJzt3XuUHHWZxvHvQ0K4r6CMCkkgUQPH\nrKLAEFhFHAE1AU1QQZMVBZc1i2tE1FXiZbMYdA/gbd1jXA3IomgIiC6OGDfoQvSgC2aCkSUJ0TEE\nM4bLcBXkGnj3j6pg0XRPV8/0JfnN8zmnT7qqfl3vWzXpp2uqe7oUEZiZWVp26HQDZmbWfA53M7ME\nOdzNzBL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AvFbVzuu/CbgrIla1sk6VunsBs4DJwL7AbpJObkPdqj9nSZ8EtpDt87bVbbd29lGl\n1lhgL+AI4KPA5fnRdLu09LlcTTufy8ORfLhL2pHsP+F3IuL7hfljgbcCl7WzbsES4G2tqF3wamCm\npI3AUuBoSd9ucU2AY4FbI2IwIp4Avg+8qpUFh/g5nwK8CXhn5CdI21G33drZR41aA8D3I/Mrst8U\n925lH4V+WvpcLqEdz+WGJR3u+ZHDN4B1EfHFisXHArdExEC76kqaUhg2E7il2bWLIuLjETEhIiaR\nXdf2moho+RE02emYIyTtmu+LY8jOzbbEEPt7OnAWMDMiHm5X3XZrZx9D1LoSODofcwAwjvZ9a2LL\nnsu1tPu5PCydfke3lTfgSLI3Om4CVue34/JlFwOnt7Mu2dHOzfn8H5K9+daufdFDmz4tk9f7NNl/\n+JuBS8g/RdHm/d0PbCrMa+onGoao+xayI9nHgDuB5S3e1zX/n7dxX48Dvp3/vG8Ejm5B7UvJ3sN5\nIt+/p+XzW/ZcrlW3k8/lsjd//YCZWYKSPi1jZjZaOdzNzBLkcDczS5DD3cwsQQ53M7MEOdzNzBLk\ncDczS9D/A7FX/jyOxZ4EAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model = embedded_method.gbt_importance(X_train=X_train,y_train=y_train,\n",
    "                             max_depth=10,top_n=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['mean perimeter', 'mean smoothness', 'mean symmetry', 'worst texture',\n",
       "       'worst perimeter', 'worst area', 'worst concavity',\n",
       "       'worst concave points'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# select features whose importance > threshold\n",
    "\n",
    "# only 8 features have importance > 0.01\n",
    "feature_selection = SelectFromModel(model, threshold=0.01,prefit=True) \n",
    "selected_feat = X_train.columns[(feature_selection.get_support())]\n",
    "selected_feat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
